package com.ehotting.edsta.diagnosisPredict.controller;

import com.ehotting.eaf.core.domain.R;
import com.ehotting.edsta.diagnosisPredict.domain.dto.TrainingModelDataDto;
import com.ehotting.edsta.diagnosisPredict.feign.TrainingFeignService;
import com.ehotting.edsta.diagnosisPredict.utils.CommonUtils;
import feign.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 训练模型表
 */
@Api(tags = "TrainingController",description = "训练模型表接口")
@RestController
@RequestMapping("training")
public class TrainingController {

    @Autowired
    private TrainingFeignService trainingFeignService;

    /**
     * 获取模型详情
     * @param projectId
     * @return
     */
    @ApiOperation(value = "获取模型详情",notes = "返回的数据类型：TrainingModelDataDto")
    @ApiResponses(value = {
            @ApiResponse(code = 1,message = "",response = TrainingModelDataDto.class)
    })
    @GetMapping(value = "/find-by-projectId/{projectId}")
    public R<TrainingModelDataDto> findByProjectId(@PathVariable("projectId") Long projectId){
        return R.convert(trainingFeignService.findByProjectId(projectId));
    }

    /**
     * 下载
     * @param id
     * @return
     */
    @ApiOperation(value = "下载",notes = "返回的数据类型：二进制流")
    @GetMapping(value = "/model-data-sdk/{id}")
    public void modelDataSdk(@PathVariable("id") Long id, HttpServletResponse response){
        Response feignResponse = trainingFeignService.modelDataSdk(id);
        CommonUtils.downloadFileFromFeign(response,"",feignResponse);
    }

    /**
     * 点击发布
     * @param taskId
     * @return
     */
    @ApiOperation(value = "点击发布",notes = "返回的数据类型：TrainingModelDataDto")
    @GetMapping(value = "/find-by-training-task/{taskId}")
    public R<TrainingModelDataDto> findByTrainingTask(@PathVariable("taskId") Long taskId){
        return R.convert(trainingFeignService.findByTrainingTask(taskId));
    }

}